package com.sx.manage.controller.system;

import java.io.IOException;

import javax.annotation.Resource;
import javax.servlet.ServletException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sx.manage.controller.base.MBaseController;
import com.sx.manage.service.sys.IMBaseSystemConfigInfoService;
import com.sx.manage.service.sys.IMSystemConfigInfoService;
import com.sx.manage.service.system.config.MSystemConfigWebService;
import com.sx.manage.servlet.ViewAndModel;
import com.sx.model.manage.mybatis.form.sys.MSystemConfigInfoForm;
import com.sx.model.manage.mybatis.vo.result.ResultBooleanVO;
import com.sx.model.manage.mybatis.vo.result.ResultListVO;
import com.sx.model.manage.mybatis.vo.sys.MSysConfigVO;

/**
 * 系统参数配置
 * 
 * @author lenovo
 *
 */

@Controller
@RequestMapping("/systemConfig")
public class MSystemConfigController extends MBaseController {

	/**
	 * 日志
	 */
	private Logger log = LoggerFactory.getLogger(this.getClass());

	@Resource(name = "mBaseSystemConfigInfoServiceImpl")
	private IMBaseSystemConfigInfoService mBaseSystemConfigInfoServiceImpl;

	@Resource(name = "systemConfigInfoServiceImpl")
	private IMSystemConfigInfoService systemConfigInfoServiceImpl;

	@Resource(name = "mSystemConfigWebService")
	private MSystemConfigWebService mSystemConfigWebService;

	/**
	 * [SystemConfig]添加页面 进入
	 * 
	 * @return
	 * @throws ServletException
	 * @throws IOException
	 */
	@RequestMapping("/toAdd")
	public ViewAndModel addViewSystemConfig() {
		log.info("系统参数配置添加界面");
		ViewAndModel model = new ViewAndModel(request, cache);
		// 如需在添加页需要加载元素在此处增加
		return this.mSystemConfigWebService.toAddViewSystemConfig(model);
	}

	/**
	 * [SystemConfig]添加 编辑 流程
	 * 
	 * @return
	 * @throws ServletException
	 * @throws IOException
	 */
	@RequestMapping("/add")
	@ResponseBody
	public ResultBooleanVO addSystemConfig(MSystemConfigInfoForm form) {

		if (null != form.getId()) {
			log.info("系统参数配置添加form={}", form);
			return this.systemConfigInfoServiceImpl.editSystemConfig(form, loginConsumer());
		} else {
			log.info("系统参数配置编辑form={}", form);
			return this.systemConfigInfoServiceImpl.addSystemConfig(form, loginConsumer());
		}
	}

	/**
	 * [SystemConfig]编辑页面 进入
	 * 
	 * @return
	 * @throws ServletException
	 * @throws IOException
	 */
	@RequestMapping("/toEdit/{id}")
	@ResponseBody
	public ViewAndModel editViewSystemConfig(MSystemConfigInfoForm form) {
		log.info("系统参数配置编辑界面form={}", form);
		// 如需在添加页需要加载元素在此处增加
		return this.mSystemConfigWebService.toEditViewSystemConfig(this.createView(), form);

	}

	/**
	 * [SystemConfig]删除 流程
	 * 
	 * @return
	 * @throws ServletException
	 * @throws IOException
	 */
	@RequestMapping("/del")
	@ResponseBody
	public ResultBooleanVO delSystemConfig(MSystemConfigInfoForm form) {
		log.info("系统参数配置删除form={}", form);
		return this.systemConfigInfoServiceImpl.delBystemConfig(form, this.loginConsumer());
	}

	/**
	 * [SystemConfig]查询页面 进入
	 * 
	 * @return
	 * @throws ServletException
	 * @throws IOException
	 */
	@RequestMapping("/showindex")
	public ViewAndModel searchViewSysIntroduceInfo() {
		log.info("系统参数配置首页");
		ViewAndModel model = new ViewAndModel(request, cache);
		// 如需在添加页需要加载元素在此处增加
		model.setViewName("sysSetting/sysSetting");// 修改ftl页面名称
		return model;
	}

	/**
	 * [SystemConfig]查询列表分页 流程
	 * 
	 * @param vo
	 * @param start
	 * @param length
	 * @return
	 * @throws ServletException
	 * @throws IOException
	 */
	@RequestMapping("/page")
	@ResponseBody
	public ResultListVO<MSysConfigVO> searchSystemConfig(MSystemConfigInfoForm form) {
		log.debug("系统参数配置列表数据查询form={}", form);
		if ("".equals(form.getConfig_name())) {
			form.setConfig_name(null);
		}
		if ("".equals(form.getConfig_desc())) {
			form.setConfig_desc(null);
		}
		return this.mBaseSystemConfigInfoServiceImpl.search_systemConfig(form);
	}

}
